package com.example.basic.web.controller.pda;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.notice.InNotice;
import com.example.basic.web.model.remains.RemainsInfo;
import com.example.basic.web.response.*;
import com.example.basic.web.service.pda.PdaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;


@Api(value = "PDA相关操作", tags = {"PDA"})
@RestController
@RequestMapping("/api/v1/byg/pda")
public class PdaController {

    @Resource
    private PdaService pdaService;

    @Log(title = "PDA", description = "遗体列表")
    @ApiOperation(value = "遗体列表", notes = "遗体列表")
    @PostMapping("/waitInList")
    public Result<List<RemainsInfo>> waitInList(
            @ApiParam(name = "searchParam", value = "模糊搜索(拼音码,五笔码,名称)") @RequestParam(required = false) String searchParam) {
        return ResultGenerator.genSuccessResult(pdaService.waitInList(searchParam));
    }

    @Log(title = "PDA", description = "绑定遗体信息详情")
    @ApiOperation(value = "绑定遗体信息详情", notes = "绑定遗体信息详情")
    @PostMapping("/bindingDetail")
    public Result<BindingInfoResponse> bindingDetail(
            @ApiParam(name = "deviceCode", value = "设备编码") @RequestParam(required = false) String deviceCode,
            @ApiParam(name = "remainsCode", value = "遗体编码") @RequestParam(required = false) String remainsCode) {
        return ResultGenerator.genSuccessResult(pdaService.bindingDetail(deviceCode,remainsCode));
    }


    @Log(title = "PDA", description = "绑定遗体信息")
    @ApiOperation(value = "绑定遗体信息", notes = "绑定遗体信息")
    @PostMapping("/binding")
    public Result<BindingInfoResponse> binding(
            @ApiParam(name = "deviceCode", value = "设备编码") @RequestParam String deviceCode,
            @ApiParam(name = "remainsCode", value = "遗体编码") @RequestParam String remainsCode) {
        return ResultGenerator.genSuccessResult(pdaService.binding(deviceCode,remainsCode));
    }

    @Log(title = "PDA", description = "入库通知单列表")
    @ApiOperation(value = "入库通知单列表", notes = "入库通知单列表")
    @PostMapping("/noticeList")
    public Result<IPage<PdaNoticeResponse>> noticeList(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "type", value = "类型，1-待发起，2-已发起,为空查询全部") @RequestParam(defaultValue = "0") String type,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<PdaNoticeResponse> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(pdaService.noticeList(queryPage,searchParam,type));
    }

    @Log(title = "平面库业务处理", description = "绑定信息查询")
    @ApiOperation(value = "绑定信息查询", notes = "绑定信息查询")
    @PostMapping("/judgeDocument")
    public Result<BindingInfoResponse> judgeDocument(
            @ApiParam(name = "deviceCode", value = "设备编码") @RequestParam(required = false) String deviceCode,
            @ApiParam(name = "remainsCode", value = "遗体编码") @RequestParam(required = false) String remainsCode,
            @ApiParam(name = "status", value = "扫码所在操作") @RequestParam String status) {
        return ResultGenerator.genSuccessResult(pdaService.judgeDocument(deviceCode,remainsCode,status));
    }

    @Log(title = "平面库业务处理", description = "任务完成")
    @ApiOperation(value = "任务完成", notes = "任务完成")
    @PostMapping("/finishInstruct")
    public Result<Boolean> finishInstruct(
            @ApiParam(name = "documentNo", value = "单据号") @RequestParam String documentNo,
            @ApiParam(name = "remainsCode", value = "遗体编码") @RequestParam(required = false) String remainsCode,
            @ApiParam(name = "status", value = "扫码所在操作") @RequestParam String status) throws IOException {
        return ResultGenerator.genSuccessResult(pdaService.finishInstruct(documentNo,remainsCode,status));
    }

    @Log(title = "PDA", description = "遗体信息详情")
    @ApiOperation(value = "遗体信息详情", notes = "遗体信息详情")
    @PostMapping("/remainsInfo")
    public Result<BindingInfoResponse> remainsInfo(
            @ApiParam(name = "remainsCode", value = "遗体编码") @RequestParam String remainsCode) {
        return ResultGenerator.genSuccessResult(pdaService.remainsInfo(remainsCode));
    }

    @Log(title = "PDA", description = "入库上架")
    @ApiOperation(value = "入库上架", notes = "入库上架")
    @PostMapping("/inPharm")
    public Result<Boolean> inPharm(@ApiParam(name = "inNotice", value = "模型", required = true) @RequestBody InNotice inNotice) {
        return ResultGenerator.genSuccessResult(pdaService.inPharm(inNotice));
    }

    @Log(title = "PDA", description = "担架板出库")
    @ApiOperation(value = "担架板出库", notes = "担架板出库")
    @PostMapping("/stretcherOut")
    public Result<Boolean> stretcherOut(
            @ApiParam(name = "deviceCode", value = "设备编码") @RequestParam String deviceCode) throws IOException {
        return ResultGenerator.genSuccessResult(pdaService.stretcherOut(deviceCode));
    }

    @Log(title = "PDA", description = "担架板入库")
    @ApiOperation(value = "担架板入库", notes = "担架板入库")
    @PostMapping("/stretcherIn")
    public Result<Boolean> stretcherIn(
            @ApiParam(name = "deviceCode", value = "设备编码") @RequestParam String deviceCode) throws IOException {
        return ResultGenerator.genSuccessResult(pdaService.stretcherIn(deviceCode));
    }

    /**
     * 临时接口
     * @param startAdress
     * @return
     * @throws IOException
     */
    @Log(title = "PDA", description = "临时接口")
    @ApiOperation(value = "瞻仰-火化间", notes = "瞻仰-火化间")
    @PostMapping("/tempTest")
    public Result<Boolean> tempTest(
            @ApiParam(name = "startAdress", value = "开始地址") @RequestParam String startAdress,
            @ApiParam(name = "remainsCode", value = "遗体编码") @RequestParam String remainsCode
            ) throws IOException {
        pdaService.tempTest(startAdress,remainsCode);
        return ResultGenerator.genSuccessResult(true);
    }
}

